package Day4.ZuoYe.Compang;
//1:公司有公司名称，注册地址，电话，经营范围等属性，公司有很多员工（用Map存储），员工有姓名，年龄，性别，职务，薪水、
// 工号等属性，公司有招聘员工（要求工号不能重复），有输出员工信息，以及辞退员工，和统计公司人数,获得公司薪水最高的员工的方法
//用oo的思想模拟（用之前的while循环的那种方式),功能有新人入职，开除员工，输出员工信息等功能。

import java.util.*;

public class Compang {
    private String name, address, telephone, businessScope;//公司名称，注册地址，电话，经营范围
    Map<String, Staff> m = new HashMap<>();

    public Compang() {
    }

    public Compang(String name, String address, String telephone, String businessScope) {
        this.name = name;
        this.address = address;
        this.telephone = telephone;
        this.businessScope = businessScope;
        this.m = m;
    }

    //加员工
    public boolean addStaff(String s, Staff staff) {
        if (m.containsKey(s))
            return false;
        m.put(s, staff);
        return true;
    }

    //查看员工信息
    public void showStaff() {
        System.out.println("工号   姓名   性别   年龄   职务    薪资");
        Set<Map.Entry<String, Staff>> s = m.entrySet();
        Iterator<Map.Entry<String, Staff>> t = s.iterator();
        while (t.hasNext()) {
            Object next = t.next();
            Object key = ((Map.Entry) next).getKey();
            Object value = ((Map.Entry) next).getValue();
            System.out.println(key + "  " + value);
        }
    }

    //辞退员工
    public boolean deleteStaff(String no) {
        if (m.size() == 0) {
            System.out.println("公司无员工！");
            return false;
        }
        Set<Map.Entry<String, Staff>> s = m.entrySet();
        Iterator<Map.Entry<String, Staff>> t = s.iterator();
        while (t.hasNext()) {
            Object next = t.next();
            Object key = ((Map.Entry) next).getKey();
            if (key.equals(no)) {
                m.remove(key);
                return true;
            }
        }
        return false;
    }

    //统计员工人数
    public int peopleCount() {
        return m.size();
    }

    //公司薪水最高的员工
    public Object highestSalary() {
        Staff staff = null;
        if (m.isEmpty())
            return staff;
        double max = 0;
        String no = null;
        Iterator<Map.Entry<String, Staff>> it = m.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Staff> next = it.next();
            String key = next.getKey();
            Staff s = next.getValue();
            if (max < s.getSalary()) {
                max = s.getSalary();
                staff = s;
                no = key;
            }
        }
        return no + " " + staff;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getBusinessScope() {
        return businessScope;
    }

    public void setBusinessScope(String businessScope) {
        this.businessScope = businessScope;
    }

    public Map<String, Staff> getM() {
        return m;
    }

    public void setM(Map<String, Staff> m) {
        this.m = m;
    }


}
